
public class Player {

	private int life;
	private int M;
	private int N;
	private int[][] copyTable;
	public int score =0;
	
	
	public Player(int life, int M,int N, int[][] copyTable){
		this.life = life;
		this.M = M;
		this.N = N;
		this.copyTable = copyTable;
		move();
		Game.table = this.copyTable;
	}
	
	private void move(){
		if(copyTable[M][N] != 0){
			score += copyTable[M][N];
			copyTable[M][N] = 0;
		}
		for(int l =0; l<life;l++){
			boolean canGo = false;
			while(canGo == false){
				int dir = (int) (Math.random()*(4)+1);
				if(dir == 1 || dir == 3){
					if(dir(dir) < 0 || dir(dir) > copyTable[0].length -1){
						//System.out.println(returnDirString(dir) + " se provali");
						canGo = false;
					}else{
						//System.out.println(returnDirString(dir));
						N = dir(dir);
						canGo = true;
					}
				}else{
					if(dir(dir) < 0 || dir(dir) > copyTable.length -1){
						//System.out.println(returnDirString(dir) + " se provali");
						canGo = false;
					}else{
						//System.out.println(returnDirString(dir));
						M = dir(dir);
						canGo = true;
					}
				}
			}
			//System.out.println(M + " m, " + N + " n");
			if(copyTable[M][N] != 0){
				score += copyTable[M][N];
				copyTable[M][N] = 0;
			}
		}
	}
	
	private int dir(int dir){
		if(dir == 1){
			return N-1;
		}else if(dir == 2){
			return M+1;
		}else if(dir == 3){
			return N+1;
		}else if(dir == 4){
			return M-1;
		}else{
			return 0;
		}
	}
	
	private String returnDirString(int dir){
		if(dir == 1){
			return "left";
		}else if(dir == 2){
			return "down";
		}else if(dir == 3){
			return "right";
		}else if(dir == 4){
			return "up";
		}else{
			return "nada";
		}
	}
	//1=left
	//2=down
	//3=right
	//4=up
}
